#! /usr/bin/env python
# -*- coding:utf-8 -*-
# author:无涯

import  json
from login import Login
from thrift.transport import  TSocket
from thrift.transport import  TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
import  socket

class LoginThrift(object):
   def __init__(self):
      pass

   def sayMsg(self,msg):
      '''获取到来自客户端的请求信息'''
      return msg

   def invoke(self,status,token,isActive,data):
      if status==0:
         return json.dumps({'status':status,'token':token,'isActive':isActive,'data':json.loads(data)})
      else:
         return '请求参数错误，请检查！'

if __name__ == '__main__':
   handler=LoginThrift()
   processor=Login.Processor(handler)
   transport=TSocket.TServerSocket('127.0.0.1',12305)
   tfactory=TTransport.TBufferedTransportFactory()
   pfactory=TBinaryProtocol.TBinaryProtocolFactory()
   server=TServer.TSimpleServer(processor,transport,tfactory,pfactory)
   print('Starting server...')
   server.serve()